/*
This file creates the following tables:
Table 1
Table 3
Figure 1
Table A.I
Table A.II
Table A.III
Table A.V
*/


**** Set Globals
clear
global home "C:\Users\venator\Dropbox\" // REPLACE WITH LOCATION OF REPLICATION FOLDER
global data "${home}\icflm_replication_archive\Data\ACS"
global output  "${home}\icflm_replication_archive\Output"
****
use  "$data/acs_base_02132024", clear

replace bpl_sp = 99 if bpl_sp == .
g miss_bpl_sp = bpl_sp == 99

g nevermarried = marst == 6
local amens `"college unemp violent property pop govt_exp s_t_ratio cooling"'
local amens_prev `"college_prev unemp_prev violent_prev property_prev pop_prev govt_exp_prev s_t_ratio_prev cooling_prev"'
local amens_bpl `"college_bpl unemp_bpl violent_bpl property_bpl pop_bpl govt_exp_bpl s_t_ratio_bpl cooling_bpl"'


local controls `"i.year black hispan age age_2 hs some_coll coll grad `amens_prev' married   "'

*****************Begin Running Linear Probability Models*****************
************effects of first child on home migration************
replace home_mig = home_mig*100  if home_mig <=1 //conversion to 100 -- eases interpretation
replace wifehome_mig = wifehome_mig*100 if wifehome_mig <=1

** Create leaving home probability
replace leavehome_mig = 100*((wifesame_state_prev == 1 & wifesame_state == 0) | (hussame_state_prev == 1 & hussame_state == 0) )
//su home_mig if !same_state_prev [aweight = perwt]
//su home_mig if !same_state_prev & married [aweight = perwt]
//su home_mig if !same_state_prev & !married [aweight = perwt]



summ mctoddler_prev
replace cc_state_std_prev = (mctoddler_prev - `r(mean)')/`r(sd)'
summ mctoddler_current
replace cc_state_std_current = (mctoddler_current - `r(mean)')/`r(sd)'
summ mctoddler_bpl
replace cc_state_std_bpl = (mctoddler_bpl - `r(mean)')/`r(sd)'


**** TABLE 1: Timing of  First Pregnancy and Home Migration Probability

*** Store means
sum home_mig if !same_state_prev [aweight = perwt]
local m1= r(mean)
sum home_mig if !same_state_prev & married [aweight = perwt]
local m2= r(mean)
sum home_mig if !same_state_prev & !married [aweight = perwt]
local m3= r(mean)
sum home_mig if !same_state_prev & white [aweight = perwt]
local m4= r(mean)
sum home_mig if !same_state_prev & black [aweight = perwt]
local m5= r(mean)
sum home_mig if !same_state_prev & non_wb [aweight = perwt]
local m6= r(mean)

eststo clear
eststo: reghdfe home_mig preg_first black non_wb age age_2 hs some_coll coll grad married if !same_state_prev [aweight = perwt], absorb(year bpl statefips statefips_prev) vce(robust)
eststo: reghdfe home_mig preg_first black non_wb age age_2 hs some_coll coll grad  if !same_state_prev & !married [aweight = perwt], absorb(year bpl statefips statefips_prev) vce(robust)
eststo: reghdfe home_mig preg_first black non_wb age age_2 hs some_coll coll grad if !same_state_prev & married [aweight = perwt], absorb(year bpl statefips statefips_prev) vce(robust)
eststo: reghdfe home_mig preg_first age age_2 hs some_coll coll grad if !same_state_prev & white [aweight = perwt], absorb(year bpl statefips statefips_prev) vce(robust)
eststo: reghdfe home_mig preg_first  age age_2 hs some_coll coll grad if !same_state_prev & black [aweight = perwt], absorb(year bpl statefips statefips_prev) vce(robust)
eststo: reghdfe home_mig preg_first age age_2 hs some_coll coll grad if !same_state_prev & non_wb [aweight = perwt], absorb(year bpl statefips statefips_prev) vce(robust)
		
	label var preg_first "First Pregnancy (FP)"
	label var cc_state_std_prev "CC Cost std."
	esttab using "$output/acs_home_mig.tex", replace keep(preg_first ) se ar2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) mtitles("All Mean = `m1'" "Non-Married Mean = `m2'" "Married Mean = `m3'" " Mean =`m4'" "Black Mean = `m5'" "Other Races Mean = `m6'") label
	
		
**** TABLE 3: Characteristics of Women in Year Following First Birth	
		g fulltime = uhrswork >= 40 
	replace fulltime = . if uhrswork == .
	
	g age_young = yngch if yngch >= 0
	global descvar age white black married coll emp fulltime ftotinc inctot 
	
	eststo clear
	estpost summarize $descvar [aweight = perwt] if mig == 0 & same_state == 1 & preg_first == 1
	eststo home_nomove
	estpost summarize $descvar [aweight = perwt] if mig == 1 & same_state == 1 & preg_first == 1
	eststo home_move
	estpost summarize $descvar [aweight = perwt] if same_state_prev != 1 & same_state != 1 & preg_first == 1
	eststo nonhome
	estpost summ $descvar[aweight = perwt] if  preg_first == 1
	eststo all 
	
	label var age "Age"
	label var white "White"
	label var black "Black"
	label var married "Married"
	label var coll "College"
	label var emp "Currently Employed"
	label var fulltime "Worked Full-Time, Prev. Year"
	label var ftotinc "Family Income, Prev. Year"
	label var inctot "Own Income, Prev. Year"
	
	
	 esttab home_nomove home_move nonhome all using "$output\descriptives_first_preg.tex", ///
		 main(mean) aux(sd) unstack nonumbers mtitles("Non-Move Home" "Mover Home" "Non-Home" "All" ) ///
		label title("Summary Statistics") replace 
****  TABLE 4: Child Care Costs in Destination of Move by Presence of Children 
	summ mctoddler_current if mig & !same_state [aweight = perwt]
	local m1= r(mean)
	summ mctoddler_current if mig & !same_state & !married [aweight = perwt]
	local m2= r(mean)
	summ mctoddler_current if mig & !same_state & married [aweight = perwt]
	local m3= r(mean)
	summ mctoddler_current if mig & !same_state & white [aweight = perwt]
	local m4= r(mean)
	summ mctoddler_current if mig & !same_state & black [aweight = perwt]
	local m5= r(mean)
	summ mctoddler_current if mig & !same_state & non_wb [aweight = perwt]
	local m6= r(mean)
	eststo clear
	eststo: reghdfe mctoddler_current baby black non_wb age age_2 hs some_coll coll grad married if mig & !same_state [aweight = perwt], absorb(year bpl statefips_prev) vce(robust)
	eststo: reghdfe mctoddler_current baby black non_wb age age_2 hs some_coll coll grad  if mig & !same_state & !married [aweight = perwt], absorb(year bpl statefips_prev) vce(robust)
	eststo: reghdfe mctoddler_current baby black non_wb age age_2 hs some_coll coll grad if mig & !same_state & married [aweight = perwt], absorb(year bpl statefips_prev) vce(robust)
	eststo: reghdfe mctoddler_current baby age age_2 hs some_coll coll grad married if mig & !same_state & white [aweight = perwt], absorb(year bpl statefips_prev) vce(robust)
	eststo: reghdfe mctoddler_current baby  age age_2 hs some_coll coll grad married if mig & !same_state & black [aweight = perwt], absorb(year bpl statefips_prev) vce(robust)
	eststo: reghdfe mctoddler_current baby age age_2 hs some_coll coll grad married if mig & !same_state & non_wb [aweight = perwt], absorb(year bpl statefips_prev) vce(robust)
	
	esttab using "$output/acs_cc_cost.tex", replace keep(baby) se ar2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) mtitles("All Mean = `m1'" "Non-Married Mean = `m2'" "Married Mean = `m3'" " Mean =`m4'" "Black Mean = `m5'" "Other Races Mean = `m6'") label
	
	eststo: reghdfe mctoddler_current baby age age_2 hs some_coll coll grad married if mig & !same_state & non_wb [aweight = perwt], absorb(year bpl statefips_prev) vce(robust)
	
	esttab using "$output/acs_cc_cost.tex", replace keep(baby) se ar2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) mtitles("All Mean = `m1'" "Non-Married Mean = `m2'" "Married Mean = `m3'" " Mean =`m4'" "Black Mean = `m5'" "Other Races Mean = `m6'") label
	



*** FIGURE 1. Home Migration Rates by Age of Child

g age_young2 = yngch
replace age_young2 = 7 if yngch >= 7 & yngch != .
preserve
keep if same_state_prev != 1
keep if nchild <= 1
collapse (mean) home_mig [w=perwt], by(age_young2 )
ren home_mig home_mig_all
tempfile all
save `all'
restore

preserve
keep if same_state_prev != 1
keep if nchild <= 1
keep if married
collapse (mean) home_mig [w=perwt], by(age_young2 )
ren home_mig home_mig_married
tempfile married
save `married'
restore
preserve
keep if same_state_prev != 1
keep if nchild <= 1
keep if !married
collapse (mean) home_mig [w=perwt], by(age_young2 )
ren home_mig home_mig_unmarr
merge 1:1 age_young2 using `all', keep(match) nogen
merge 1:1 age_young2 using `married', keep(match) nogen


twoway connected home_mig_all age_young2, ms(circle) ///
|| connected home_mig_married age_young2, ms(diamond) ///
|| connected home_mig_unmarr age_young2, ms(square) ytitle("Home Migration Likelihood") bgcolor(white) graphregion(color(white)) ///
xtitle("Age of Child") xlabel(-1 "N/A" 0(1) 6 7 ">6") legend(lab(1 "All") lab(2 "Married") lab(3 "Unmarried"))
graph export "$output/home_mig_probs.png", replace
restore


**** TABLE A.I Timing of First Pregnancy and Migration from Home Probability	
	*** Store means
sum leavehome_mig if !same_state_prev [aweight = perwt]
local m1= r(mean)
sum leavehome_mig if !same_state_prev & married [aweight = perwt]
local m2= r(mean)
sum leavehome_mig if !same_state_prev & !married [aweight = perwt]
local m3= r(mean)
sum leavehome_mig if !same_state_prev & white [aweight = perwt]
local m4= r(mean)
sum leavehome_mig if !same_state_prev & black [aweight = perwt]
local m5= r(mean)
sum leavehome_mig if !same_state_prev & non_wb [aweight = perwt]
local m6= r(mean)

	eststo clear
	eststo: reghdfe leavehome_mig preg_first black non_wb age age_2 hs some_coll coll grad married if same_state_prev [aweight = perwt], absorb(year bpl statefips statefips_prev) vce(robust)
	eststo: reghdfe leavehome_mig preg_first black non_wb age age_2 hs some_coll coll grad  if same_state_prev & !married [aweight = perwt], absorb(year bpl statefips statefips_prev) vce(robust)
	eststo: reghdfe leavehome_mig preg_first black non_wb age age_2 hs some_coll coll grad if same_state_prev & married [aweight = perwt], absorb(year bpl statefips statefips_prev) vce(robust)
	eststo: reghdfe leavehome_mig preg_first age age_2 hs some_coll coll grad if same_state_prev & white [aweight = perwt], absorb(year bpl statefips statefips_prev) vce(robust)
	eststo: reghdfe leavehome_mig preg_first  age age_2 hs some_coll coll grad if same_state_prev & black [aweight = perwt], absorb(year bpl statefips statefips_prev) vce(robust)
	eststo: reghdfe leavehome_mig preg_first age age_2 hs some_coll coll grad if same_state_prev & non_wb [aweight = perwt], absorb(year bpl statefips statefips_prev) vce(robust)
		
	label var preg_first "First Pregnancy (FP)"
	label var cc_state_std_prev "CC Cost std."
	esttab using "$output/acs_leavehome_mig.tex", replace keep(preg_first ) se ar2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) mtitles("All Mean = `m1'" "Non-Married Mean = `m2'" "Married Mean = `m3'" " Mean =`m4'" "Black Mean = `m5'" "Other Races Mean = `m6'") label	
	

	
*** TABLE A.II Fertility Characteristicsof Wome by Moving Status	
		
	
	eststo clear
	estpost summarize nchild age_young preg_first baby [aweight = perwt] if mig == 0 & same_state == 1
	eststo home_nomove2
	estpost summarize nchild age_young preg_first baby [aweight = perwt] if mig == 1 & same_state == 1 
	eststo home_move2
	estpost summarize nchild age_young preg_first baby [aweight = perwt] if same_state_prev != 1 & same_state != 1
	eststo nonhome2
	estpost summ  nchild age_young preg_first baby [aweight = perwt]
	eststo all2
	

	label var age_young "Age of Youngest Child"
	label var nchild "Number of Children"
	label var preg_first "First Pregnancy"
	label var baby "Child, Age 1-5"
	 esttab home_nomove2 home_move2 nonhome2 all2 using "$output\descriptives_all.tex", ///
		 main(mean) aux(sd) unstack nonumbers mtitles("Non-Move Home" "Mover Home" "Non-Home" "All" ) ///
		label title("Summary Statistics") replace 
	
	
	
**** TABLE A.III Effects of later pregnancy on home migration probability

	
*** Store means
sum home_mig if !same_state_prev [aweight = perwt]
local m1= r(mean)
sum home_mig if !same_state_prev & married [aweight = perwt]
local m2= r(mean)
sum home_mig if !same_state_prev & !married [aweight = perwt]
local m3= r(mean)
sum home_mig if !same_state_prev & white [aweight = perwt]
local m4= r(mean)
sum home_mig if !same_state_prev & black [aweight = perwt]
local m5= r(mean)
sum home_mig if !same_state_prev & non_wb [aweight = perwt]
local m6= r(mean)
	g preg_moreone = (yngch == 0  & nchild > 1)

	eststo clear
	eststo: reghdfe home_mig preg_moreone black non_wb age age_2 hs some_coll coll grad married if !same_state_prev [aweight = perwt], absorb(year bpl statefips statefips_prev) vce(robust)
	eststo: reghdfe home_mig preg_moreone black non_wb age age_2 hs some_coll coll grad  if !same_state_prev & !married [aweight = perwt], absorb(year bpl statefips statefips_prev) vce(robust)
	eststo: reghdfe home_mig preg_moreone black non_wb age age_2 hs some_coll coll grad if !same_state_prev & married [aweight = perwt], absorb(year bpl statefips statefips_prev) vce(robust)
	eststo: reghdfe home_mig preg_moreone age age_2 hs some_coll coll grad if !same_state_prev & white [aweight = perwt], absorb(year bpl statefips statefips_prev) vce(robust)
	eststo: reghdfe home_mig preg_moreone age age_2 hs some_coll coll grad if !same_state_prev & black [aweight = perwt], absorb(year bpl statefips statefips_prev) vce(robust)
	eststo: reghdfe home_mig preg_moreone age age_2 hs some_coll coll grad if !same_state_prev & non_wb [aweight = perwt], absorb(year bpl statefips statefips_prev) vce(robust)
		
	
	label var preg_moreone "Later Pregnancy"
	label var cc_state_std_prev "CC Cost std."
	esttab using "$output/acs_home_mig_moreone.tex", replace keep(preg_moreone ) se ar2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) mtitles("All Mean = `m1'" "Non-Married Mean = `m2'" "Married Mean = `m3'" " Mean =`m4'" "Black Mean = `m5'" "Other Races Mean = `m6'") label	
	
		

***** TABLE A.V Effects if Children and Location on Hours Worked
replace uhrswork = 0 if emp == 0 //fixing hours worked
su uhrswork [aweight = perwt]
su uhrswork if !married [aweight = perwt]
su uhrswork if married [aweight = perwt]
local amens `"college unemp violent property pop govt_exp s_t_ratio cooling"'
local amens_prev `"college_prev unemp_prev violent_prev property_prev pop_prev govt_exp_prev s_t_ratio_prev cooling_prev"'
local amens_bpl `"college_bpl unemp_bpl violent_bpl property_bpl pop_bpl govt_exp_bpl s_t_ratio_bpl cooling_bpl"'
local controls `"i.year black hispan age* hs some_coll coll grad `amens_prev' married i.bpl"'


	eststo clear
	eststo: reghdfe uhrswork black non_wb age age_2 hs some_coll coll grad baby c.cc_state_std_prev same_state_prev ib0.baby##ib0.married [aweight=perwt], vce(robust) absorb(year bpl statefips_prev)
	eststo: reghdfe uhrswork black non_wb age age_2 hs some_coll coll grad baby c.cc_state_std_prev same_state_prev ib0.baby##ib0.married ib0.baby##c.cc_state_std_prev ib0.baby##ib0.same_state_prev [aweight=perwt], vce(robust) absorb(year bpl statefips_prev)	
	eststo: reghdfe uhrswork black non_wb age age_2 hs some_coll coll grad baby c.cc_state_std_prev same_state_prev ib0.baby##c.cc_state_std_prev ib0.baby##ib0.same_state_prev [aweight=perwt] if !married, vce(robust) absorb(year bpl statefips_prev)	
	eststo: reghdfe uhrswork black non_wb age age_2 hs some_coll coll grad baby c.cc_state_std_prev same_state_prev ib0.baby##c.cc_state_std_prev ib0.baby##ib0.same_state_prev college_prev unemp_prev violent_prev property_prev pop_prev govt_exp_prev s_t_ratio_prev cooling_prev [aweight=perwt] if married & year <= 2017, vce(robust) absorb(year bpl )	
		esttab using "$output/acs_hrs.tex", replace keep(baby  1.married cc_state_std_prev same_state_prev 1.baby#1.married 1.baby#c.cc_state_std_prev 1.baby#1.same_state_prev) se ar2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) mtitles("All" "All"  "Non-Married" "Married") label
	
	
	
	